<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title>重置密码</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover" />
		<link href="css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="css/register.css" />
		<script src="js/jquery.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/mui.min.js"></script>
	</head>
	<body style="background:#fff">
		<header class="mui-bar mui-bar-nav">
			<div style="height: 20px;"></div>
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">重置密码</h1>
		</header>
		<div class="mui-content mainRe">
			<div class="mainText" style="margin-top:64px;">
				<div class="mui-input-row mainLine">
					<label class="mail">邮箱</label>
					<input type="text" class="info_email" placeholder="请输入您的邮箱地址">
				</div>
				<div class="mui-input-row mainLine" style="position:relative;border-bottom: none;">
					<label class="pm">验证码</label>
					<input type="text" class="lineBottom email_code" placeholder="请输入您收到的验证码">
					<div class="mesM">
						<input class="ym password_getcode" readonly="readonly" type="text" value="获取验证码">
					</div>
				</div>
				<div class="mui-input-row mainLine">
					<label class="cpw">重置密码</label>
					<input type="password" class="password_password" placeholder="请设置您的新密码">
				</div>
				<div class="mui-input-row mainLine">
					<label class="pw">确认密码</label>
					<input type="password" class="password_true" placeholder="请再次输入您的新密码">
				</div>
				<div class="mainButton">
					<button type="button" class="mui-btn mui-btn-blue password_btn" style="line-height:.5">确认</button>
				</div>
			</div>

		</div>

		<script type="text/javascript">
			mui.init();
			var _url = 'http://112.54.80.235:8038';
			/* 验证码 
			$('.mesM .ym').on('tap',function(){
				$(this).addClass('meHidden');
				$(this).siblings('span').removeClass('meHidden');
				var num = 5;
				$('.mesM .num').text(num);
				//每隔1s num--
				var myNum;
				function myFun (){
					myVar = setInterval(function(){
						num--;
						$('.mesM .num').text(num);
						if(num == 0){
							clearInterval(myVar);
							$('.mesM .ym').removeClass('meHidden');
							$('.mesM .ym').siblings('span').addClass('meHidden');
						}
					},1000)
				};
				myFun ();
				
			});
		
			$('.mainButton button').on('tap',function(e){
				mui.openWindow({
					url:'login.html',
					id:'login.html'
				})
			});*/
			mui.plusReady(function() {
				//关闭等待框
				plus.nativeUI.closeWaiting();
				//获取邮箱验证码
				$('.ym').on('tap', function() {
					var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
					var val = mui(".info_email")[0].value;
					var ema = '"' + val + '"';
					if (!reg.test(val)) {
						mui.toast('请输入正确的邮箱地址')
						return false;
					};
					var time = 60;
					$('.ym').attr("disabled", true);
					var myVar = setInterval(function() {
						if (time > 1) {
							time--;
							mui('.ym')[0].value = time + "秒后重新获取"
						} else {
							clearInterval(myVar);
							$('.ym').attr("disabled", false)
							mui('.ym')[0].value = "获取验证码"
						}
					}, 1000);
					$.ajax({
						url: _url + '/actionapi/Users/YouXiangYanZheng',
						type: "post",
						data: ema,
						dataType: 'json',
						contentType: "application/json; charset=utf-8",
						error: function(xhr, type, errorThrown) {
							console.log(errorThrown);
							mui.toast('验证码发送失败');
						},
						success: function(data) { //回调函数，result，返回值
							if (data.code == 1) {
								mui.toast('验证码发送成功');
							} else {
								mui.toast('验证码发送失败');
							}
						}
					})
				})
				//点击确认按钮
				mui('.password_btn')[0].addEventListener('tap', function() {
					var info_email = mui(".info_email")[0].value;
					var email_code = mui(".email_code")[0].value;
					var password = mui(".password_password")[0].value;
					var password_true = mui(".password_true")[0].value;
					var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
					if (!reg.test(info_email)) {
						mui.toast('请输入正确的邮箱地址')
						return false;
					};
					var regx = /^(?!([a-zA-Z]+|\d+)$)[a-zA-Z\d]{6,20}$/;
					if (!regx.test(password)) {
						mui.toast('应包含字母和数字，且不少于6位');
						return false;
					};
					if (password != password_true) {
						mui.toast('两次输入的密码不一致');
						return false;
					};
					//更改密码ajax
					$.ajax({
						url: _url + '/actionapi/Users/GengGaiMiMa',
						type: "post",
						timeout: 5000,
						contentType: "application/json; charset=utf-8",
						data: JSON.stringify({
							phone: info_email,
							code: email_code,
							XinMiMa: password
						}),
						dataType: 'json',
						error: function(xhr, type, errorThrown) {
							//console.log(errorThrown);
							mui.toast('GengGaiMiMa接口连接失败');
						},
						success: function(data) {
							console.log(JSON.stringify(data));
							if (data.code == 1) {
								mui.toast('密码重置成功');
								mui.openWindow({
									url: "login.html",
									id: "login.html",
									waiting: {
										autoShow: true, //自动显示等待框，默认为true
										title: '正在加载...', //等待对话框上显示的提示内容
									}
								});
							} else {
								mui.toast(data.message);
							}

						}
					});
				});
				//点击获取验证码
				// mui('.password_getcode')[0].addEventListener('tap', function() {
				// 	var val = mui(".password_phone")[0].value;
				// 	if (!(/^1[34578]\d{9}$/.test(val))) {
				// 		mui.toast('请输入正确格式的手机号')
				// 		return false;
				// 	};
				// 	var time = 60;
				// 	$('.ym').attr("disabled", true)
				// 	var myVar = setInterval(function() {
				// 		if (time > 1) {
				// 			time--;
				// 			mui('.ym')[0].value = time + "秒后重新获取"
				// 		} else {
				// 			clearInterval(myVar);
				// 			$('.ym').attr("disabled", false)
				// 			mui('.ym')[0].value = "获取验证码"
				// 			time = 60
				// 		}
				// 	}, 1000);
				// 	$.ajax({
				// 		url: _url + '/actionapi/Users/GetDuanXin',
				// 		type: "post",
				// 		timeout: 5000,
				// 		contentType: "application/json; charset=utf-8",
				// 		data: val,
				// 		dataType: 'json',
				// 		error: function(xhr, type, errorThrown) {
				// 			//mui('.password_getcode')[0].removeAttribute('disabled');
				// 			mui.toast('GetDuanXin连接失败');
				// 		},
				// 		success: function(data) { //回调函数，result，返回值
				// 			$('.ym').attr("disabled", false)
				// 			if (data.code == 1) {
				// 				mui.toast('获取验证码成功');
				// 			} else {
				// 				mui.toast(data.message);
				// 			}
				// 		}
				// 	})
				// })
			})
		</script>
	</body>
</html>
